public class LinkList {
    static class ListNode {
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head; //头结点
    //1.删除链表中等于给定值val的所有节点
    public ListNode removeElements(ListNode head, int val) {
        if(head==null){
            return null;
        }
        ListNode prev=head;
        ListNode cur=head.next;
        while(cur!=null){
            if(cur.val==val){
                prev.next=cur.next;
                cur=cur.next;
            }else{
                prev=cur;
                cur=cur.next;
            }
        }
        if(head.val==val)
            head=head.next;

        return head;

    }
    //2.反转链表

    public void createMyLinkedList(){
        ListNode node1=new ListNode(1);
        ListNode node2=new ListNode(11);
        ListNode node3=new ListNode(21);
        ListNode node4=new ListNode(31);
        ListNode node5=new ListNode(41);
        node1.next=node2;
        node2.next=node3;
        node3.next=node4;
        node4.next=node5;
        node5.next=null;
        this.head=node1;
    }
    public void display() {
        ListNode cur=head;
        while(cur!=null){
            System.out.print(cur.val+" ");
            cur=cur.next;
        }
    }
}

